package com.aij.starter.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aij.starter.service.AijService;

@Configuration
@ConditionalOnClass(AijService.class)
@EnableConfigurationProperties(AijProperties.class)
public class AijConfiguration {

    private AijProperties aijProperties;

    // 自动注入配置类
    public AijConfiguration(AijProperties aijProperties) {
        this.aijProperties = aijProperties;
    }

    // 创建AijService对象，注入到Spring容器中, 当容器没有此bean时，才注册
    @Bean
    @ConditionalOnMissingBean(AijService.class)
    public AijService aijService() {
    	AijService aijService = new AijService();
    	aijService.setAijProperties(aijProperties);
        return aijService;
    }
}
